import asyncio
from none_bot_py_plugins.gen_svr import report_gen
from none_bot_py_plugins.gen_svr import create_gen
from none_bot_py_plugins.gen_svr import request_svr
from none_bot_py_plugins.gen_svr.test_gen import TestGen

finish_future = None
report_gen_name = None
report = None
create_gen_name = None
gen_manager = None
request = None


def cast_create(recv_id):
    print(create_gen_name)
    request.cast(create_gen_name, ("create", recv_id))


def request_send(recv_id, msg):
    request.cast(recv_id, msg)


async def main():
    # test_gen1 = TestGen("1")
    # test_gen2 = TestGen("2")
    #
    # task1 = asyncio.create_task(job_start(test_gen1))
    # task2 = asyncio.create_task(job_start(test_gen2))
    # task3 = asyncio.create_task(job_send(test_gen1, "2"))
    # task4 = asyncio.create_task(job_send(test_gen2, "1"))
    #
    # await asyncio.gather(task1, task2, task3, task4)

    # task1 = asyncio.create_task(test())
    # task2 = asyncio.create_task(test())
    # task3 = asyncio.create_task(test())
    # task4 = asyncio.create_task(test())
    # task5 = asyncio.create_task(test())
    global report_gen_name
    global report
    global create_gen_name
    global gen_manager
    global request

    report_gen_name, report = report_gen.manager_start()
    await asyncio.sleep(1)
    create_gen_name, gen_manager = create_gen.create_gen_start(report_gen_name)
    await asyncio.sleep(1)
    request = request_svr.request_svr_start()
    await asyncio.sleep(1)

    loop = asyncio.get_running_loop()
    global finish_future
    finish_future = loop.create_future()

    await finish_future

    # request_svr.cast_create("123456")
    # await asyncio.sleep(5)
    # request_svr.request_send(report_gen.report_svr_name("123456"), "hello")
    # await asyncio.sleep(3)
    # print("start print")
    # tasklist = [task1, task2, task3, task4, task5]
    # for i in tasklist:
    #     await i
    print("finish")

# asyncio.run(main())
